using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy01AI : Enemy
{
    [SerializeField] private GameObject weaponCollider;


    private void Update()
    {
        if(player == null || isAnimating)
        {
            return;
        }
        FlipEnemy();
        
        if (IsInAttackRange() && !animator.GetBool("Hurting"))
        {
            Attack();
        }
        if(!IsInAttackRange() && !animator.GetBool("Hurting"))
        {
            AnimateWalkAndGetDir();
        }
    }


    private void FixedUpdate()
    {
        if(animator.GetBool("Hurting"))
        {
            return;
        }
        if(!IsInAttackRange())
        {
            rb.MovePosition(rb.position + moveDir * (moveSpeed * Time.fixedDeltaTime));
        }   
    }

    private void Attack()
    {
        animator.SetBool("Walking", false);
        animator.SetTrigger("Attack");
    }

    private void SetWeaponColliderActive()
    {
        weaponCollider.SetActive(true);
    }

    private void SetWeaponColliderNotActive()
    {
        weaponCollider.SetActive(false);
    }

}
